import 'package:base_flutter_project/pages/card_page.dart';
import 'package:base_flutter_project/pages/home_page.dart';
import 'package:base_flutter_project/pages/mine_page.dart';
import 'package:base_flutter_project/pages/search_page.dart';
import 'package:base_flutter_project/pages/travel_page.dart';
import 'package:flutter/material.dart';

class TagNavigator extends StatefulWidget {
  @override
  _TagNavigatorState createState() => _TagNavigatorState();
}

class _TagNavigatorState extends State<TagNavigator> {

  final _defaultColor = Colors.grey;
  final _activeColor = Colors.blueAccent;
  var _currentIndex = 0;
  final PageController _controller = PageController(initialPage: 0);

  _bottonCreate(String title, IconData icons, int index){
    return BottomNavigationBarItem(
            icon: Icon(icons, color: _defaultColor,),
            activeIcon: Icon(icons, color: _activeColor,),
            title: Text(title,style: TextStyle(color: _currentIndex == index ? _activeColor : _defaultColor),)
          );
  }
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: PageView(
        controller: _controller,
        physics: NeverScrollableScrollPhysics(),
        onPageChanged: (index){
          setState(() {
            _currentIndex = index;
          });
        },
        children: <Widget>[
          HomePage(),
          SearchPage(),
          TravelPage(),
          MinePage(),
          CardPage()
        ],
      ),
      bottomNavigationBar: BottomNavigationBar(
        currentIndex: _currentIndex,
        type: BottomNavigationBarType.fixed,
        onTap: (index){
          _controller.jumpToPage(index);
          setState(() {
            _currentIndex = index;
          });
        },
        items: [
          _bottonCreate("首页", Icons.home, 0),
          _bottonCreate("搜索", Icons.search, 1),
          _bottonCreate("旅拍", Icons.camera_alt, 2),
          _bottonCreate("我的", Icons.account_circle, 3),
          _bottonCreate("旅游", Icons.card_travel, 4),
        ],
      ),
    );
  }
}